package com.aat.restful.springresteasy.app;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
public class AppFilter implements ContainerResponseFilter {

	@Override
	public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
			throws IOException {
		
		if ("POST".equals(requestContext.getMethod())){
			InputStream ins= requestContext.getEntityStream();
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			byte[] bs = new byte[1024];
			int i = 0;
			while ((i = ins.read(bs)) > -1) {
				bos.write(bs, 0, i);
			}
			byte[] body = bos.toByteArray();
			System.out.println("2"+new String(body));
			requestContext.setEntityStream(new ByteArrayInputStream(body));
		}
	}

}
